from starlette.applications import Starlette
from starlette.middleware.authentication import AuthenticationMiddleware
import authenticate
import config
import uvicorn
import core
import wxenterprise.wx_enterprise_controller
import wxpublic.wx_public_controller
# from background_scheduler import scheduler
import setup_log


setup_log.setup()

app = Starlette()
app.debug = config.DEBUG
app.add_middleware(AuthenticationMiddleware, backend=authenticate.JWTAuthenticationBackend(),
                   on_error=authenticate.on_auth_error)

app.mount('/api/core', core.control)
app.mount('/api/wxent', wxenterprise.wx_enterprise_controller.control)
app.mount('/api/wxpub', wxpublic.wx_public_controller.control)


# @app.on_event("startup")
# def when_app_start():
#     scheduler.start()
#
#
# @app.on_event("shutdown")
# def when_app_shutdown():
#     scheduler.shutdown()


if __name__ == '__main__':
    uvicorn.run(app, host="0.0.0.0", port=38000, loop="asyncio", log_level="debug")
